import globalVisionEntertainment.nba.MainFrame;
import globalVisionEntertainment.nba.NbaScorePredictor;

public class Program
{

	public static void main(String[] args) throws ClassNotFoundException
	{
		Class.forName("com.mysql.jdbc.Driver");
		NbaScorePredictor.verbose = true;

		if (args.length == 1 && args[0].equals("--help"))
		{
			String help = "OPTIONS:\n";
			help += "\t--date\tThe date of the game being predicting. eg. 20140821";
			help += "\t--visitor\tPlayers of visitor team. First five players are starters and the remianing are bench. Bench players may be rematched according to their average on court time.\n";
			help += "\t--home\tPlayers of home team. Quote the player name. Seperate each player by space. ";
			System.out.println(help);
			System.exit(0);
		}

		MainFrame f = new MainFrame();
		for (int i = 0; i < args.length; i++)
		{
			if (args[i].equalsIgnoreCase("--date"))
			{
				f.dateTextField.setText(args[i + 1]);
				i++;
			}
			else if (args[i].equals("--visitor"))
			{
				f.visitorStarterComboBoxes[0].setText(args[i + 1]);
				f.visitorStarterComboBoxes[1].setText(args[i + 2]);
				f.visitorStarterComboBoxes[2].setText(args[i + 3]);
				f.visitorStarterComboBoxes[3].setText(args[i + 4]);
				f.visitorStarterComboBoxes[4].setText(args[i + 5]);
				int j = 0;
				for (; j < f.visitorBenchComboBoxes.length && i + 5 + 1 + j < args.length && args[i + 5 + 1 + j].startsWith("--") == false; j++)
					f.visitorBenchComboBoxes[j].setText(args[i + 5 + 1 + j]);
				i += 5 + j;
			}
			else if (args[i].equals("--home"))
			{
				f.homeStarterComboBoxes[0].setText(args[i + 1]);
				f.homeStarterComboBoxes[1].setText(args[i + 2]);
				f.homeStarterComboBoxes[2].setText(args[i + 3]);
				f.homeStarterComboBoxes[3].setText(args[i + 4]);
				f.homeStarterComboBoxes[4].setText(args[i + 5]);
				int j = 0;
				for (; j < f.homeBenchComboBoxes.length && i + 5 + 1 + j < args.length && args[i + 5 + 1 + j].startsWith("--") == false; j++)
					f.homeBenchComboBoxes[j].setText(args[i + 5 + 1 + j]);
				i += 5 + j;
			}
			else
			{
				throw new IllegalArgumentException("Error in reading argument " + args[i] + ".");
			}

		}

		f.setVisible(true);
	}

}
